<%@ page language="java" import="java.util.*" contentType="text/html" pageEncoding="utf-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="blog1.DBBean"%>
<%@ page import="blog1.UserBean"%>
<%@ page import="javax.servlet.http.*"%>
<%@ page import="java.net.*"%>
<jsp:useBean id="myDBbean" class="blog1.DBBean"></jsp:useBean>

<jsp:useBean id="user" class="blog1.UserBean" scope="request"></jsp:useBean>
<jsp:setProperty name="user" property="*" />

<html>
  <head>
    <title>用户登录验证</title>
  </head>
  
  <body>
    <h2>用户登录验证</h2>
    <hr>
    <%
        
		String userName = user.getUserName();
		String userPwd = user.getUserPwd();
		String sql = "select * from user where name='"+userName+"' and password='"+userPwd+"';";
		if (user.isLogined()){
			out.println("您已经登录过了!");
		}else{
			ResultSet rs = myDBbean.query(sql);
			if (rs.next()){
				user.setLogined(true);
				out.println("恭喜您登录成功!");
				response.sendRedirect("user_index.jsp");
			}else{
				user.setLogined(false);
				out.println("对不起，您的帐号或密码不正确!");
		
			}					
		}			   	
    %>
  </body>
</html>